package iSOCK::Controller::Specification::Status;

use Moose;
use namespace::autoclean;

BEGIN { extends 'Catalyst::Controller' }

use iSOCK::Controller::Root;

=head1 NAME

iSOCK::Controller::Status - Status Controller for iSOCK

=head1 DESCRIPTION

[enter your description here]

=head1 METHODS

=cut

sub index :Path :Args(0) {
  my ( $self, $c ) = @_;
  
  my $session      = $c->session;
  my $session_path = iSOCK::Controller::Root->session_path ( $c );
  
  if ( $session->{xls_file} ) {
    my $xls_stem = $session->{xls_stem};

    if ( open ( my $fh, '<', "$session_path/${xls_stem}_status.html" ) ) {
      my $dhms = '';
      if ( @{$session->{session_dhms}} ) {
        $dhms  = ' in';
        $dhms .= sprintf ' %d d',  $session->{session_dhms}->[0] if $session->{session_dhms}->[0];
        $dhms .= sprintf ' %d h',  $session->{session_dhms}->[1] if $session->{session_dhms}->[1];
        $dhms .= sprintf ' %d mn', $session->{session_dhms}->[2] if $session->{session_dhms}->[2];
        $dhms .= sprintf ' %d s',  $session->{session_dhms}->[3] if $session->{session_dhms}->[3];
      }

      $c->stash ( dhms => $dhms );
      
      $c->detach ( qw( iSOCK::Controller::Root render_view ) );
    }
    else {
      $c->response->redirect ( $c->uri_for ( '/logs' ) );
    }
  }
  
  $c->response->redirect ( $c->uri_for ( '/specification/process' ) );
}

sub end : ActionClass('RenderView') {}

=head1 AUTHOR

Xavier Caron

=head1 LICENSE

This library is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.

=cut

1;
